import config from '@/config'
import type { Position } from '@/service/position'

/**
 * 声明 AbstractModel 构造函数
 */
export interface AbstractModelConstructor<T extends AbstractModel> {
    new (ctx: CanvasRenderingContext2D, position: Position): T
}

export abstract class AbstractModel {
    public x: number
    public y: number
    public width: number = config.model.width
    public height: number = config.model.height
    protected ctx: CanvasRenderingContext2D

    public constructor(ctx: CanvasRenderingContext2D, position: Position) {
        this.ctx = ctx
        this.x = position.x
        this.y = position.y
    }

    /**
     * 在画布中画模型
     */
    public draw() {
        this.ctx.drawImage(this.getImage(), this.x, this.y, this.width, this.height)
    }

    /**
     * 获得模型的名字
     */
    protected getName(): string {
        throw new Error('Method not implemented.')
    }

    /**
     * 获得模型的图片
     */
    protected abstract getImage(): HTMLImageElement
}
